import request from '@/utils/request'
import { AxiosPromise } from 'axios'

enum Api {
  list = '/system/agent/list',
  add = '/system/agent/add',
  edit = '/system/agent/edit',
  delete = '/system/agent/delete',
  batchDelete = '/system/agent/batchDelete',
  changeStatus = '/system/agent/changeStatus',
  optionSelect = '/system/agent/optionSelect',
}

// 列表
export function agentList(query?: any): AxiosPromise<any> {
  return request({
    url: Api.list,
    method: 'post',
    data: query,
  })
}

// 编辑、保存
export const agentSave = (data: any) => {
  return request({
    url: data.id ? Api.edit : Api.add,
    method: 'post',
    data,
  })
}

// 删除
export function agentDelete(id: string | Array<string>) {
  return request({
    url: Api.delete,
    method: 'post',
    data: id,
  })
}

// 批量删除
export const agentBatchDelete = (data: (string | number)[]) => {
  return request({
    url: Api.batchDelete,
    method: 'post',
    data,
  })
}

// 选项列表
export function optionSelect(query?: any): AxiosPromise<any> {
  return request({
    url: Api.optionSelect,
    method: 'post',
    data: query,
  })
}

// 状态修改
export function changeStatus(id: string | number, status: number) {
  const data = {
    id,
    status,
  }
  return request({
    url: Api.changeStatus,
    method: 'post',
    data,
  })
}
